package com.chuangyang.fixboxmaster.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.Toast;

import com.chuangyang.fixboxmaster.R;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by vanshu on 16/1/15 17:12.
 */
public class CalendarPickerActivity  extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("日历");
        setContentView(R.layout.activity_calendar_picker);
        MaterialCalendarView mMaterialCalendarView = (MaterialCalendarView) findViewById(R.id.calendarView);
        mMaterialCalendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
        mMaterialCalendarView.setSelectedDate(new Date());
        mMaterialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {
            @Override
            public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
                Toast.makeText(CalendarPickerActivity.this,   date.getDate().toGMTString(), Toast.LENGTH_SHORT).show();
                Intent intent=new Intent();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                String selectDate=    formatter.format(date.getDate());
                intent.putExtra("selectDate",selectDate);
                setResult(RESULT_OK,intent);
                finish();
            }
        });
    }
}
